package com.white.loggerserver

import android.text.format.Formatter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.white.loggerserver.room.Record
import java.io.File
import java.text.SimpleDateFormat
import java.util.*

/**
 * Created by ytf on 2020/07/24.
 * Description:
 */
class LogRecordAdapter : BaseQuickAdapter<Record, BaseViewHolder>(R.layout.item_log_record) {

    private val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA)

    override fun convert(holder: BaseViewHolder, item: Record) {
        holder.setText(R.id.name, item.title)
        holder.setText(R.id.time, "记录日期：" + sdf.format(Date(item.addTime)))
        val file = File(item.path)
        if(file.exists()){
            holder.setText(R.id.path, file.parentFile.absolutePath)
            holder.setText(R.id.size, "大小：" + Formatter.formatFileSize(context, file.length()))
        }else{
            holder.setText(R.id.path, "无文件")
            holder.setText(R.id.size, "大小：0B")
        }
    }
}